package cc.lj.internal.coupons.infrastructure.repository.mysql;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.BasePageHelper;
import cc.lj.internal.core.model.PageParam;
import cc.lj.internal.coupons.domain.ticket.repository.ITicketBatchLifecycleContinueRepository;
import cc.lj.internal.coupons.domain.ticket.repository.ITicketBatchRepository;
import cc.lj.internal.coupons.infrastructure.dao.ITicketBatchLifecycleContinueMapper;
import cc.lj.internal.coupons.infrastructure.dao.ITicketBatchMapper;
import cc.lj.internal.coupons.infrastructure.excepion.CoupousExceptionEnum;
import cc.lj.internal.coupons.infrastructure.po.MultipleModelPO;
import cc.lj.internal.coupons.infrastructure.po.TicketBatchLifecycleContinuePO;
import cc.lj.internal.coupons.infrastructure.po.TicketBatchPO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

/**
 * 电子券批次连续有效期表　mysql仓储实现
 * @author liangxifeng
 * @date 2021-12-14
 */
@Repository("ticketBatchLifecycleContinueMysqlRespository")
public class TicketBatchLifecycleContinueMysqlRespository implements ITicketBatchLifecycleContinueRepository,BasePageHelper<TicketBatchLifecycleContinuePO> {
    @Autowired
    private ITicketBatchLifecycleContinueMapper mapper;

    @Override
    public List<TicketBatchLifecycleContinuePO> getNoStartList() {
        LambdaQueryWrapper<TicketBatchLifecycleContinuePO> wrapper = new LambdaQueryWrapper<>();
        //开始日期  > 当前日期
        wrapper.gt(TicketBatchLifecycleContinuePO::getLifeStartDate, LocalDate.now());
        return mapper.selectList(wrapper);
    }

    @Override
    public List<TicketBatchLifecycleContinuePO> getList(TicketBatchLifecycleContinuePO ticketBatchLifecycleContinuePO) {
        return this.list(ticketBatchLifecycleContinuePO);
    }

    /**
     * 查询超过某个特定日期的连续有效活动
     * @param continuePO
     * @return
     * @author zhaoyong
     */
    @Override
    public List<TicketBatchLifecycleContinuePO> getListValid(TicketBatchLifecycleContinuePO continuePO) {
        QueryWrapper<TicketBatchLifecycleContinuePO> wrapper = new QueryWrapper<>();
        wrapper.ge("life_end_date",continuePO.getLifeEndDate());
        return mapper.selectList(wrapper);
    }

    @Override
    public List<TicketBatchLifecycleContinuePO> list(TicketBatchLifecycleContinuePO param) {
        QueryWrapper<TicketBatchLifecycleContinuePO> wrapper = new QueryWrapper(param);
        List<TicketBatchLifecycleContinuePO> list = mapper.selectList(wrapper);
        return list;
    }
}
